package com.huak.zookeeper.connection;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 * @author liuhuan
 * @date 2018/9/16 10:45
 * @description
 */
public class CenterChecker {
    public static boolean result=false;

    public static List<BaseDangeCenter> lists=new ArrayList<>(2);

    public static  boolean check() throws Exception{
        CountDownLatch countDownLatch=new CountDownLatch(2);
        lists.add(new BeijingStationDangeCenter(countDownLatch));
        lists.add(new ShanghaiStationDangeCenter(countDownLatch));

        Executor executor= Executors.newFixedThreadPool(lists.size());

        lists.forEach(e->executor.execute(e));

        countDownLatch.await();

        for (BaseDangeCenter baseDangeCenter:lists) {
            if(!baseDangeCenter.isOk()){
                return false;
            }
        }

        return true;
    }

    public static void main(String[] args) throws  Exception{
        result=check();
        System.out.println("调度结果为:"+result);
    }
}
